$(function() {
	$("form").DynaButton("/receive/toTest!getJSON.do");
});

(function($) {
	$.fn.DynaButton = function(url) {
		var divNode = $("<div class='myButton' />");
		var currentNode = $(this);
		divNode.appendTo(currentNode);
		$.getJSON(url, function(data) {
			var len = data.length;
			for (i = 0; i < len; i++) {
				var buttonInput = $("<input type='button'/>");
				formUrl = data[i].action;
				buttomValue = data[i].name;
				buttonInput.appendTo(divNode).val(data[i].name).bind("click", {
					url : formUrl,
					value : buttomValue
				}, doRequest);
			}
		});
		function doRequest(event) {
			var url = event.data.url;
			var value = event.data.value;
			var button = $("input[value=" + value + "]");
			var resp;
			button.ajaxStart(function() {
				alert("url====" + url);
			});
			$.get(url, function(res) {
				resp = res;
				alert("res=======" + res);
			});
		}

		return this;
	}
})(jQuery);


function categorySelect(v){
	$.getJSON("/part/category_getSubCategoryList.do?level1Id="+v.value, function(data){
      data=eval(data);
      alert("Data Loaded: " + data.level2Name);
    });
}
